﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<div class="modal-dialog x-modal-dialog" style="width:800px;">

  <div class="modal-content">

    <div class="modal-header x-breadcrumb no-bottom-border clearfix">

      <h2><i class="glyphicon glyphicon-fire"></i>&nbsp;&nbsp;<span>编辑产品&nbsp;-&nbsp;基本信息</span></h2>

      <button type="button" class="close" data-dismiss="modal">&times;</button>

    </div>

    <form class="form-horizontal" method="POST" action="${ctx.host}/products/${product.id}" data-validate="true">
    
      <input type="hidden" name="_method" value="PATCH">
      <input type="hidden" name="productId" value="${product.id}">
      
      <div class="modal-body">
        <c:choose>
            <c:when test="${product.type.online}">
                <div class="form-group x-form-group">
                  <label class="col-xs-2 control-label">产品名称</label>
                  <div class="pull-left col-xs-4" style="width: 40%;">
                    <p class="form-control-statc">${product.name}</p>
                  </div>
                </div>
            </c:when>
            <c:otherwise>
                <div class="form-group x-form-group">
                  <label class="col-xs-2 control-label">产品名称</label>
                  <div class="pull-left col-xs-4" style="width: 60%;">
                    <input type="text" name="name" value="${product.name}" class="form-control" data-validate="required">
                  </div>
                </div>
            </c:otherwise>
        </c:choose>
        
        <div class="form-group x-form-group">
          <label class="col-xs-2 control-label">产品现价</label>
          <div class="pull-left col-xs-4" style="width: 30%;">
            <input type="text" class="form-control" name="currentOffer" value="${product.currentOffer / 100}" data-validate="required|float" />
          </div>
          <label class="col-xs-2 control-label">产品原价</label>
          <div class="pull-left col-xs-4" style="width: 30%;">
            <input type="text" class="form-control" name="basicOffer" value="${product.basicOffer / 100}" data-validate="required|float" />
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-2 control-label">产品分享链接</label>
          <div class="pull-left col-xs-4" style="width: 60%;">
            <input type="text" class="form-control" name="shareUrl" value="${product.shareUrl}"/>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-2 control-label">产品简介</label>
          <div class="pull-left col-xs-9" style="width: 77%;">
            <textarea name="summary" rows="5" style="width: 100%;">${product.summary}</textarea>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-2 control-label">产品标签</label>
          <div class="pull-left col-xs-4" style="width: 30%;">
            <select name="inputTags" class="form-control" multiple>
              <option value=""></option>
              <c:forEach var="productTag" items="${enums['productTag']}">
                <c:choose>
                  <c:when test="${product.tags.containsKey(productTag.alias)}">
                    <option value="${productTag.alias}" selected>${productTag.description}</option>
                  </c:when>
                  <c:otherwise>
                    <option value="${productTag.alias}">${productTag.description}</option>
                  </c:otherwise>
                </c:choose>
                  
              </c:forEach>
            </select>
          </div>
          <label class="col-xs-2 control-label">产品类别</label>
          <div class="pull-left col-xs-4" style="width: 30%;">
            <select name="category" class="form-control" data-validate="required">
              <option value=""></option>
              <c:forEach var="productType" items="${enums['productType']}">
                <optgroup label="${productType.description}">
                  <c:forEach var="category" items="${persist.productCategoriesMapping[productType.name]}">
                    <c:if test="${not category.disabled}">                    
                      <option value="${category.id}" ${category.id eq product.category.id ? 'selected' : ''}>${category.name}</option>
                    </c:if>
                  </c:forEach>
                </optgroup>
              </c:forEach>
            </select>
          </div>
        </div>
        
        <c:if test="${product.type.alias!= 'others'}">
          <div class="form-group x-form-group">
            <label class="col-xs-2 control-label">产品课程</label>
            <div class="pull-left col-xs-4" style="width: 30%;">
              <select name="course" class="form-control" data-validate="required">
                <option value=""></option>
                <c:forEach var="course" items="${persist.courses}">
                  <option value="${course.id}" ${course.id eq product.course.id ? 'selected' : ''}>${course.name}</option>
                </c:forEach>
              </select>
            </div>
            <label class="col-xs-2 control-label">产品状态</label>
            <div class="pull-left col-xs-4" style="width: 30%;">
              <p class="form-control-static"><label class="label label-${product.status.css} label-outline">${product.status.des}</label></p>
            </div>
          </div>
        </c:if>
        <div class="form-group x-form-group">
          <label class="col-xs-2 control-label">第三方关键字</label>
          <div class="pull-left col-xs-4" style="width: 60%;">
            <input type="text" name="thirdParty" value="${product.thirdParty}" class="form-control">
          </div>
        </div>
        
        <c:if test="${product.type.others}">
          <div class="form-group x-form-group">
            <label class="col-xs-2 control-label">第三方链接</label>
            <div class="pull-left col-xs-4" style="width: 60%;">
              <input type="text" name="address" value="${product.address}" class="form-control" data-validate="www">
            </div>
          </div>
        </c:if>
        
        <c:if test="${product.type.offline}">
        <div class="form-group x-form-group">
          <label class="col-xs-2 control-label">可购买门店</label>
          <div class="pull-left col-xs-4" style="width: 60%;">
            <select name="siteIds" class="form-control" data-validate="required" multiple>
              <option value=""></option>
              <c:forEach var="site" items="${persist.sites}">
                <option value="${site.id}" ${product.siteIdsAsLong.contains(site.id) ? 'selected' : ''}>${site.name}</option>
              </c:forEach>
            </select>
          </div>
        </div>
        </c:if>
        
      </div>

      <div class="modal-footer">
        <button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
      </div>
    </form>

  </div>

</div>

<script>
$(document).ready(function(){
  
  $('select[name="type"]').select2({
    placeholder : '请选择产品父类',
    minimumResultsForSearch : 5,
    allowClear : true,
  });
  
  $('select[name="inputCategory"]').select2({
    placeholder : '请选择产品子类',
    minimumResultsForSearch : 5,
    allowClear : true,
  });
  
  $('select[name="inputTags"]').select2({
    placeholder : '请选择产品标签',
    minimumResultsForSearch : 5,
    allowClear : true,
  });
  
  $('select[name="course"]').select2({
    placeholder : '请选择产品课程',
    minimumResultsForSearch : 5,
    allowClear : true,
  });
  
  $('select[name="siteIds"]').select2({  
    placeholder : '请选择可购买门店',
    minimumResultsForSearch : 5,
    allowClear : true,
  })
  
  
});
</script>